package cloud.demarcia.rabbitregister.controller;

import cloud.demarcia.rabbitregister.service.RegisterService;
import cloud.demarcia.rabbitregister.vo.UserRegisterVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author Bojun Wen, wen_bj@outlook.com
 * @date 2022.02.09
 */
@RestController
@CrossOrigin
@Slf4j
public class RegisterController {
    @Resource
    private RegisterService registerService;

    @PostMapping("/register")
    public ResponseEntity<String> register(@RequestBody @Valid UserRegisterVo vo){
        log.info("注册请求：user:{},email:{},pass:{}.",vo.getUsername(),vo.getEmail(),vo.getPassword());
        registerService.register(vo);
        return ResponseEntity.ok().build();
    }
    @PostMapping("/verification")
    public ResponseEntity<String> sendCode(@RequestBody String email){
        registerService.sendVerificationCode(email);
        return ResponseEntity.ok().build();
    }

}
